package apiday05.homework;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * 完成一个简易的记事本工具
 * 要求:
 * 程序启动后,将用户在控制台上输入的每一行内容都[按行]写入到文件note.txt中
 * 当用户单独输入了"exit"则程序退出
 */
public class IODemo {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos = new FileOutputStream("note.txt",true);
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        PrintWriter pw = new PrintWriter(osw);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入内容：（单独输入'exit'退出,不区分大小写）");
        String str;
//        while(!"exit".equalsIgnoreCase(str = sc.nextLine())){
//             pw.println(str);
//        }
        while (true) {
            str = sc.nextLine();
            if ("exit".equalsIgnoreCase(str.trim())) {
                break;
            }
            pw.println(str);
        }
        System.out.println("写入操作执行完毕！");
        sc.close();
        pw.close();
    }
}
